package com.onLineCar.manages.pojo.dto;

import com.onLineCar.common.security.utils.SecurityUtils;
import com.onLineCar.manages.pojo.ImageTable;
import com.onLineCar.manages.pojo.RideHailingCarInfo;
import com.onLineCar.manages.pojo.VehicleInfo;
import com.onLineCar.manages.pojo.dto.vehicleinfo.RideHailingCarInfoDTOBean;
import com.onLineCar.manages.pojo.dto.vehicleinfo.VehicleDocumentPhotosBean;
import com.onLineCar.manages.pojo.dto.vehicleinfo.VehicleInfoDTOBean;
import com.onLineCar.manages.pojo.imageenum.ImageEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@NoArgsConstructor
@Data
public class VehicleBaseInfoDTO {
    /**
     * vehicleInfoDTO : {"cityId":110000,"vehicleLevelId":2,"vehicleTypeId":7,"vinCode":"1231","licensePlate":"123","installedVehicleBrain":"0","vehicleBrainBrand":"123","vehicleBrainCode":"123","largeScreenBrand":"123","largeScreenCode":"132","vehicleStatus":"0"}
     * vehicleDocumentPhotos : {"invoicePhoto":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/fae84e928164418db54138bb8b242cc1c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","licensePlatePhoto":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/29a397f9caff42668edf4cb7786b0946c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","drivingLicensePhoto":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/e1894dbf2dda4b5689a9bbdba2adb6c9c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","registrationCertificatePhoto":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/ea199bb3dfe444af904e889aed0528b4c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","taxCertificatePhoto":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/e5a71dcac56f47e794638e46df4d82f1c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","transportCertificatePhoto":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/5ce0f69b6878437a9f1ff63345fa2f4ec829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","other1Photo":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/cea5e18f3ed442fc86bd6a5c5d94a3d5c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png","other2Photo":"http://zhucaiyi.oss-cn-beijing.aliyuncs.com/2023/12/13/5aa873a657534e098c232436a7bc7b56c829920ffc484b148dbd4ac0a96ba473未命名文件 (26).png"}
     * rideHailingCarInfoDTO : {"vehicleIdId":"123","brand":"123","type":"123","owner":"123","color":"123","engineNumber":"132","registrationDate":"2023-12-13","displacement":"123","photoFileNumber":"123","transportCertificateNumber":"213","transportCertificateIssuingAuthority":"123","operatingArea":"123","transportCertificateValidFrom":"2023-12-13","transportCertificateValidTo":"2023-12-13","firstRegistrationDate":"2023-12-14","nextAnnualInspectionDate":"2023-12-14","invoicePrinterSerialNumber":"123","gpsBrand":"123","gpsModel":"213","gpsImei":"123","gpsInstallationDate":"2023-12-13","reportDate":"2023-12-14","serviceClass":"123"}
     */

    private VehicleInfoDTOBean vehicleInfoDTO;
    private VehicleDocumentPhotosBean vehicleDocumentPhotos;
    private RideHailingCarInfoDTOBean rideHailingCarInfoDTO;

    public VehicleInfo convertVehicleInfo(VehicleInfoDTOBean vehicleInfoDTO) {
        VehicleInfo vehicleInfo = new VehicleInfo();
        vehicleInfo.setCityId(vehicleInfoDTO.getCityId());
        vehicleInfo.setVehicleLevelId(vehicleInfoDTO.getVehicleLevelId().longValue());
        vehicleInfo.setVehicleTypeId(vehicleInfoDTO.getVehicleTypeId().longValue());
        vehicleInfo.setVinCode(vehicleInfoDTO.getVinCode());
        vehicleInfo.setLicensePlate(vehicleInfoDTO.getLicensePlate());
        vehicleInfo.setCreatedBy(SecurityUtils.getUsername());
        vehicleInfo.setInstalledVehicleBrain(Integer.parseInt(vehicleInfoDTO.getInstalledVehicleBrain()));
        vehicleInfo.setVehicleStatus(vehicleInfoDTO.getVehicleStatus());
        vehicleInfo.setVehicleBrainBrand(vehicleInfoDTO.getVehicleBrainBrand());
        vehicleInfo.setVehicleBrainCode(vehicleInfoDTO.getVehicleBrainCode());
        vehicleInfo.setLargeScreenBrand(vehicleInfoDTO.getLargeScreenBrand());
        vehicleInfo.setLargeScreenCode(vehicleInfoDTO.getLargeScreenCode());
        return vehicleInfo;
    }

    public VehicleInfoDTOBean convertVehicleInfoDTO(VehicleInfo vehicleInfo) {
        VehicleInfoDTOBean vehicleInfoDTOBean = new VehicleInfoDTOBean();
        vehicleInfoDTOBean.setCityId(vehicleInfo.getCityId());
        vehicleInfoDTOBean.setVehicleLevelId(vehicleInfo.getVehicleLevelId().intValue());
        vehicleInfoDTOBean.setVehicleTypeId(vehicleInfo.getVehicleTypeId().intValue());
        vehicleInfoDTOBean.setVinCode(vehicleInfo.getVinCode());
        vehicleInfoDTOBean.setLicensePlate(vehicleInfo.getLicensePlate());
        vehicleInfoDTOBean.setInstalledVehicleBrain(vehicleInfo.getInstalledVehicleBrain().toString());
        vehicleInfoDTOBean.setVehicleStatus(vehicleInfo.getVehicleStatus());
        vehicleInfoDTOBean.setVehicleBrainBrand(vehicleInfo.getVehicleBrainBrand());
        vehicleInfoDTOBean.setVehicleBrainCode(vehicleInfo.getVehicleBrainCode());
        vehicleInfoDTOBean.setLargeScreenBrand(vehicleInfo.getLargeScreenBrand());
        vehicleInfoDTOBean.setLargeScreenCode(vehicleInfo.getLargeScreenCode());
        return vehicleInfoDTOBean;
    }

    public RideHailingCarInfo convertRideHailingCarInfo(RideHailingCarInfoDTOBean rideHailingCarInfoDTO) {
        RideHailingCarInfo rideHailingCarInfo = new RideHailingCarInfo();
        rideHailingCarInfo.setVehicleId(rideHailingCarInfoDTO.getVehicleId());
        rideHailingCarInfo.setCompany(rideHailingCarInfoDTO.getCompany());
        rideHailingCarInfo.setColor(rideHailingCarInfoDTO.getColor());
        rideHailingCarInfo.setBrand(rideHailingCarInfoDTO.getBrand());
        rideHailingCarInfo.setType(rideHailingCarInfoDTO.getType());
        rideHailingCarInfo.setOwner(rideHailingCarInfoDTO.getOwner());
        rideHailingCarInfo.setEngineNumber(rideHailingCarInfoDTO.getEngineNumber());
        rideHailingCarInfo.setAnnualInspectionStatus(rideHailingCarInfoDTO.getAnnualInspectionStatus());
        rideHailingCarInfo.setRegistrationDate(rideHailingCarInfoDTO.getRegistrationDate());
        rideHailingCarInfo.setDisplacement(rideHailingCarInfoDTO.getDisplacement());
        rideHailingCarInfo.setPhotoFileNumber(rideHailingCarInfoDTO.getPhotoFileNumber());
        rideHailingCarInfo.setBrand(rideHailingCarInfoDTO.getBrand());
        rideHailingCarInfo.setTransportCertificateNumber(rideHailingCarInfoDTO.getTransportCertificateNumber());
        rideHailingCarInfo.setTransportCertificateIssuingAuthority(rideHailingCarInfoDTO.getTransportCertificateIssuingAuthority());
        rideHailingCarInfo.setOperatingArea(rideHailingCarInfoDTO.getOperatingArea());
        rideHailingCarInfo.setTransportCertificateValidFrom(rideHailingCarInfoDTO.getTransportCertificateValidFrom());
        rideHailingCarInfo.setTransportCertificateValidTo(rideHailingCarInfoDTO.getTransportCertificateValidTo());
        rideHailingCarInfo.setFirstRegistrationDate(rideHailingCarInfoDTO.getFirstRegistrationDate());
        rideHailingCarInfo.setNextAnnualInspectionDate(rideHailingCarInfoDTO.getNextAnnualInspectionDate());
        rideHailingCarInfo.setInvoicePrinterSerialNumber(rideHailingCarInfoDTO.getInvoicePrinterSerialNumber());
        rideHailingCarInfo.setGpsBrand(rideHailingCarInfoDTO.getGpsBrand());
        rideHailingCarInfo.setGpsModel(rideHailingCarInfoDTO.getGpsModel());
        rideHailingCarInfo.setGpsImei(rideHailingCarInfoDTO.getGpsImei());
        rideHailingCarInfo.setGpsInstallationDate(rideHailingCarInfoDTO.getGpsInstallationDate());
        rideHailingCarInfo.setReportDate(rideHailingCarInfoDTO.getReportDate());
        rideHailingCarInfo.setServiceClass(rideHailingCarInfoDTO.getServiceClass());
        rideHailingCarInfo.setCreatorName(SecurityUtils.getUsername());
        rideHailingCarInfo.setModifierName(SecurityUtils.getUsername());
        rideHailingCarInfo.setFuelType(rideHailingCarInfoDTO.getFuelType());


        rideHailingCarInfo.setMaintenanceStatus(rideHailingCarInfoDTO.getMaintenanceStatus());

        return rideHailingCarInfo;
    }

    public RideHailingCarInfoDTOBean convertRideHailingCarInfoDTOBean(RideHailingCarInfo rideHailingCarInfo) {
        RideHailingCarInfoDTOBean rideHailingCarInfoDTOBean = new RideHailingCarInfoDTOBean();
        rideHailingCarInfoDTOBean.setVehicleId(rideHailingCarInfo.getVehicleId());
        rideHailingCarInfoDTOBean.setCompany(rideHailingCarInfo.getCompany());
        rideHailingCarInfoDTOBean.setColor(rideHailingCarInfo.getColor());
        rideHailingCarInfoDTOBean.setBrand(rideHailingCarInfo.getBrand());
        rideHailingCarInfoDTOBean.setType(rideHailingCarInfo.getType());
        rideHailingCarInfoDTOBean.setOwner(rideHailingCarInfo.getOwner());
        rideHailingCarInfoDTOBean.setEngineNumber(rideHailingCarInfo.getEngineNumber());
        rideHailingCarInfoDTOBean.setAnnualInspectionStatus(rideHailingCarInfo.getAnnualInspectionStatus());
        rideHailingCarInfoDTOBean.setRegistrationDate(rideHailingCarInfo.getRegistrationDate());
        rideHailingCarInfoDTOBean.setDisplacement(rideHailingCarInfo.getDisplacement());
        rideHailingCarInfoDTOBean.setPhotoFileNumber(rideHailingCarInfo.getPhotoFileNumber());
        rideHailingCarInfoDTOBean.setBrand(rideHailingCarInfo.getBrand());
        rideHailingCarInfoDTOBean.setTransportCertificateNumber(rideHailingCarInfo.getTransportCertificateNumber());
        rideHailingCarInfoDTOBean.setTransportCertificateIssuingAuthority(rideHailingCarInfo.getTransportCertificateIssuingAuthority());
        rideHailingCarInfoDTOBean.setOperatingArea(rideHailingCarInfo.getOperatingArea());
        rideHailingCarInfoDTOBean.setTransportCertificateValidFrom(rideHailingCarInfo.getTransportCertificateValidFrom());
        rideHailingCarInfoDTOBean.setTransportCertificateValidTo(rideHailingCarInfo.getTransportCertificateValidTo());
        rideHailingCarInfoDTOBean.setFirstRegistrationDate(rideHailingCarInfo.getFirstRegistrationDate());
        rideHailingCarInfoDTOBean.setNextAnnualInspectionDate(rideHailingCarInfo.getNextAnnualInspectionDate());
        rideHailingCarInfoDTOBean.setInvoicePrinterSerialNumber(rideHailingCarInfo.getInvoicePrinterSerialNumber());
        rideHailingCarInfoDTOBean.setGpsBrand(rideHailingCarInfo.getGpsBrand());
        rideHailingCarInfoDTOBean.setGpsModel(rideHailingCarInfo.getGpsModel());
        rideHailingCarInfoDTOBean.setGpsImei(rideHailingCarInfo.getGpsImei());
        rideHailingCarInfoDTOBean.setGpsInstallationDate(rideHailingCarInfo.getGpsInstallationDate());
        rideHailingCarInfoDTOBean.setReportDate(rideHailingCarInfo.getReportDate());
        rideHailingCarInfoDTOBean.setServiceClass(rideHailingCarInfo.getServiceClass());
        rideHailingCarInfoDTOBean.setFuelType(rideHailingCarInfo.getFuelType());


        rideHailingCarInfoDTOBean.setMaintenanceStatus(rideHailingCarInfo.getMaintenanceStatus());

        return rideHailingCarInfoDTOBean;
    }

    public VehicleDocumentPhotosBean convertVehicleDocumentPhotosBean(List<ImageTable> imageTables) {
        VehicleDocumentPhotosBean vehicleDocumentPhotos = new VehicleDocumentPhotosBean();
        imageTables.forEach(imageTable -> {
            int type = ImageEnum.getImageTypeByImageName(imageTable.getDescription());
            switch (type) {
                case 13:
                    vehicleDocumentPhotos.setTransportCertificatePhoto(imageTable.getImageUrl());
                    break;
                case 14:
                    vehicleDocumentPhotos.setInvoicePhoto(imageTable.getImageUrl());
                    break;
                case 15:
                    vehicleDocumentPhotos.setLicensePlatePhoto(imageTable.getImageUrl());
                    break;
                case 16:
                    vehicleDocumentPhotos.setDrivingLicensePhoto(imageTable.getImageUrl());
                    break;
                case 17:
                    vehicleDocumentPhotos.setRegistrationCertificatePhoto(imageTable.getImageUrl());
                    break;
                case 18:
                    vehicleDocumentPhotos.setTaxCertificatePhoto(imageTable.getImageUrl());
                    break;
                case 19:
                    vehicleDocumentPhotos.setTransportCertificatePhoto(imageTable.getImageUrl());
                    break;
                case 20:
                    vehicleDocumentPhotos.setOther1Photo(imageTable.getImageUrl());
                    if (StringUtils.isNoneBlank(vehicleDocumentPhotos.getOther1Photo())){
                        vehicleDocumentPhotos.setOther2Photo(imageTable.getImageUrl());
                    }
                    break;
                default:break;
            }
        });
        return vehicleDocumentPhotos;
    }
}
